package simple

func maxScore(s string) int {

	score := 0
	index := 1
	for index < len(s) {

		curScore := 0
		left := s[0:index]
		right := s[index:len(s)]
		for _, l := range left {
			if l == '0' {
				curScore++
			}
		}
		for _, r := range right {
			if r == '1' {
				curScore++
			}
		}
		if curScore > score {
			score = curScore
		}
		index++
	}

	return score
}

func maxScorePrefix(s string) int {

	maxCount := 0
	zeroCount, oneCount := 0, 0

	for _, v := range s {
		if v == '1' {
			oneCount++
		}
	}
	for _, v := range s[:len(s)-1] {
		if v == '0' {
			zeroCount++
		} else {
			oneCount--
		}
		if maxCount < oneCount+zeroCount {
			maxCount = oneCount + zeroCount
		}
	}

	return maxCount
}
